#ifndef __TABLEFILE_H__
#define __TABLEFILE_H__

#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include "TableRecord.h"
#include "Constants.h"

using namespace std;

class TableFile {

private:
	fstream file;
	int fd;
	struct flock fl;
	string path;

	string getDefaultTableFile();
	void init(string path, bool trunc);

public:
	TableFile(bool trunc);
	TableFile(string path, bool trunc);
	virtual ~TableFile();

	TableRecord getNextRecord();
	void addRecord(TableRecord record);
	bool isEOF();
	long int currentPosition();
	void goTo(long int position);
	void goToEnd();
	int getWriteLock();
	int getReadLock();
	int unlock();
};

#endif /* __TABLEFILE_H__ */
